package com.letu.log.point;

import com.letu.annotation.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "PointEnum", description = "埋点类型")
public enum PointEnum implements BaseEnum {
    /**
     * SYSLOG="接口日志"
     */
    SYSLOG("接口日志"),

    /**
     * POINTBUSINESSLOG="单业务埋点"
     */
    POINTBUSINESSLOG("单业务埋点"),


    /**
     * POINTLOG="埋点日志"
     */
    POINTLOG("埋点日志"),
    /**
     * POINTDATALOG="数据埋点"
     */
    POINTDATALOG("数据埋点"),

    /**
     * POINTORDERBUSINESSLOG="顺序业务埋点"
     */
    POINTORDERBUSINESSLOG("顺序业务埋点"),

    /**
     * POINTMESSAGELOG="消息中心埋点"
     */
    POINTMESSAGELOG("消息中心埋点"),
    /**
     * POINTBROADLOG="广播埋点"
     */
    POINTBROADLOG("广播埋点"),
    /**
     * TRANSACTIONLOG="事务埋点"
     */
    TRANSACTIONLOG("事务埋点");

    @ApiModelProperty(value = "描述")
    private String desc;

    /**
     * 根据当前枚举的name匹配
     */
    public static PointEnum match(String val, PointEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static PointEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(PointEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "NORMAL,WAIT_INIT,FORBIDDEN,WAITING,REFUSE,DELETE", example = "NORMAL")
    public String getCode() {
        return this.name();
    }
}
